package com.shaozi.nc.manage.observer;

import java.util.Observable;
import java.util.Observer;

import org.apache.log4j.Logger;

import com.shaozi.nc.aop.MQBusAop;
import com.shaozi.nc.manage.observer.base.BaseSecretaryObserver;
import com.shaozi.data.mq.business.base.SourceTypeConsts.OA.Task;
import com.shaozi.data.mq.business.observer.MqTargetObserverBean;

/**
 * 任务观察者 https://shimo.im/doc/BESz6u08M9Ap3Ju7
 * 
 * @author lyx
 *
 */
public class TaskObserver extends BaseSecretaryObserver implements Observer {

	private Logger logger = Logger.getLogger(MQBusAop.class);

	// 查看任务 7001,7003,7005,7015,7017,7018,7051
	private static final Integer[] Rule_Look_Report_sourceType = { Task.Created, Task.Status, Task.Actor,
			Task.AddComment, Task.ReplyComment, Task.Principal, Task.Alarm };
	// 评论/回复评论 7015,7017
	private static final Integer[] Reply_or_Comment_sourceType = { Task.AddComment, Task.ReplyComment };

	@Override
	public void update(Observable o, Object arg) {
		if (arg != null) {
			if (arg instanceof MqTargetObserverBean) {
				MqTargetObserverBean mqBean = (MqTargetObserverBean) arg;
				int sourceType = mqBean.getSourceType();
				switch (sourceType) {
				case Task.Rule_Look_Report:// 查看任务
					updateUserRead(sourceType, mqBean, Rule_Look_Report_sourceType);
					break;
				case Task.AddComment:
				case Task.ReplyComment:// 评论/回复评论
					updateUserRead(sourceType, mqBean, Reply_or_Comment_sourceType);
					break;
				default:
					break;
				}
			}
		}
	}

}
